﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OracleDataToRedis.Domain;
using OracleDataToRedis.Utils;

namespace OracleDataToRedis.Coders.WinFroms
{
    public class EditDialogsDesignerCoder
    {
        public static void Write(DbTable dt)
        {

            string path = Path.Combine(BaseParams.WinFromsPath, "EditDialogs");
            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }

            #region 创建类detail文件

            string className = Path.Combine(path, "dlg" + dt.TitleCaseName + "Edit.Designer.cs");
            FileStream file = new FileStream(className, FileMode.Create);
            StreamWriter sw = new StreamWriter(file, Encoding.UTF8);
            CommentsCoder.CreateCsComments(dt.Comments, sw);

            sw.WriteLine("namespace " + BaseParams.WinFromsNameSpace + ".EditDialogs");
            sw.WriteLine("{");
            sw.WriteLine("    partial class dlg" + dt.TitleCaseName + "Edit");
            sw.WriteLine("    {");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 必需的设计器变量。");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        private System.ComponentModel.IContainer components = null;");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 清理所有正在使用的资源。");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"disposing\">如果应释放托管资源,为 true；否则为 false。</param>");
            sw.WriteLine("        protected override void Dispose(bool disposing)");
            sw.WriteLine("        {");
            sw.WriteLine("            if (disposing && (components != null))");
            sw.WriteLine("            {");
            sw.WriteLine("                components.Dispose();");
            sw.WriteLine("            }");
            sw.WriteLine("            base.Dispose(disposing);");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        #region Windows 窗体设计器生成的代码");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 设计器支持所需的方法 - 不要");
            sw.WriteLine("        /// 使用代码编辑器修改此方法的内容。");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        private void InitializeComponent()");
            sw.WriteLine("        {");
            sw.WriteLine("            this.components = new System.ComponentModel.Container();");
            sw.WriteLine("            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(dlg" + dt.TitleCaseName + "Edit));");
            sw.WriteLine("            this.btnSave = new " + BaseParams.ControlsNameSpace + ".MyButton();");
            sw.WriteLine("            this.btnCancel = new " + BaseParams.ControlsNameSpace + ".MyButton();");
            sw.WriteLine("            this.btnClose = new " + BaseParams.ControlsNameSpace + ".MyButton();");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + " = new System.Windows.Forms.BindingNavigator(this.components);");
            sw.WriteLine("            this.bindingNavigatorCountItem = new System.Windows.Forms.ToolStripLabel();");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem = new System.Windows.Forms.ToolStripButton();");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem = new System.Windows.Forms.ToolStripButton();");
            sw.WriteLine("            this.bindingNavigatorSeparator = new System.Windows.Forms.ToolStripSeparator();");
            sw.WriteLine("            this.bindingNavigatorPositionItem = new System.Windows.Forms.ToolStripTextBox();");
            sw.WriteLine("            this.bindingNavigatorSeparator1 = new System.Windows.Forms.ToolStripSeparator();");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem = new System.Windows.Forms.ToolStripButton();");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem = new System.Windows.Forms.ToolStripButton();");
            sw.WriteLine("            this.myPanel1 = new " + BaseParams.ControlsNameSpace + ".MyPanel();");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1 = new " + BaseParams.UserControlsNameSpace + ".Details.Uc" + dt.TitleCaseName + "Detail();");
            sw.WriteLine("            ((System.ComponentModel.ISupportInitialize)(this.bindingNavigator" + dt.TitleCaseName + ")).BeginInit();");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".SuspendLayout();");
            sw.WriteLine("            this.myPanel1.SuspendLayout();");
            sw.WriteLine("            this.SuspendLayout();");
            sw.WriteLine("            // ");
            sw.WriteLine("            // btnSave");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.btnSave.Location = new System.Drawing.Point(249, 3);");
            sw.WriteLine("            this.btnSave.Name = \"btnSave\";");
            sw.WriteLine("            this.btnSave.Size = new System.Drawing.Size(85, 23);");
            sw.WriteLine("            this.btnSave.TabIndex = 0;");
            sw.WriteLine("            this.btnSave.Text = \"保存/下一条\";");
            sw.WriteLine("            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // btnCancel");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.btnCancel.CausesValidation = false;");
            sw.WriteLine("            this.btnCancel.Location = new System.Drawing.Point(358, 3);");
            sw.WriteLine("            this.btnCancel.Name = \"btnCancel\";");
            sw.WriteLine("            this.btnCancel.Size = new System.Drawing.Size(85, 23);");
            sw.WriteLine("            this.btnCancel.TabIndex = 1;");
            sw.WriteLine("            this.btnCancel.TabStop = false;");
            sw.WriteLine("            this.btnCancel.Text = \"取消修改\";");
            sw.WriteLine("            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // btnClose");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.btnClose.CausesValidation = false;");
            sw.WriteLine("            this.btnClose.Location = new System.Drawing.Point(467, 3);");
            sw.WriteLine("            this.btnClose.Name = \"btnClose\";");
            sw.WriteLine("            this.btnClose.Size = new System.Drawing.Size(85, 23);");
            sw.WriteLine("            this.btnClose.TabIndex = 2;");
            sw.WriteLine("            this.btnClose.TabStop = false;");
            sw.WriteLine("            this.btnClose.Text = \"退出\";");
            sw.WriteLine("            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigator" + dt.TitleCaseName + "");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".AddNewItem = null;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".CountItem = this.bindingNavigatorCountItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".DeleteItem = null;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Dock = System.Windows.Forms.DockStyle.Bottom;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Items.AddRange(new System.Windows.Forms.ToolStripItem[] {");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem,");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem,");
            sw.WriteLine("            this.bindingNavigatorSeparator,");
            sw.WriteLine("            this.bindingNavigatorPositionItem,");
            sw.WriteLine("            this.bindingNavigatorCountItem,");
            sw.WriteLine("            this.bindingNavigatorSeparator1,");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem,");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem});");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Location = new System.Drawing.Point(0, 34);");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".MoveFirstItem = this.bindingNavigatorMoveFirstItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".MoveLastItem = this.bindingNavigatorMoveLastItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".MoveNextItem = this.bindingNavigatorMoveNextItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".MovePreviousItem = this.bindingNavigatorMovePreviousItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Name = \"bindingNavigator" + dt.TitleCaseName + "\";");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".PositionItem = this.bindingNavigatorPositionItem;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Size = new System.Drawing.Size(455, 25);");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".TabIndex = 2;");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".Text = \"bindingNavigator1\";");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".MouseEnter += new System.EventHandler(this.bindingNavigator" + dt.TitleCaseName + "_MouseEnter);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorCountItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorCountItem.Name = \"bindingNavigatorCountItem\";");
            sw.WriteLine("            this.bindingNavigatorCountItem.Size = new System.Drawing.Size(35, 22);");
            sw.WriteLine("            this.bindingNavigatorCountItem.Text = \"/ {0}\";");
            sw.WriteLine("            this.bindingNavigatorCountItem.ToolTipText = \"总项数\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorMoveFirstItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.Image = ((System.Drawing.Image)(resources.GetObject(\"bindingNavigatorMoveFirstItem.Image\")));");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.Name = \"bindingNavigatorMoveFirstItem\";");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true;");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.Size = new System.Drawing.Size(23, 22);");
            sw.WriteLine("            this.bindingNavigatorMoveFirstItem.Text = \"移到第一条记录\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorMovePreviousItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.Image = ((System.Drawing.Image)(resources.GetObject(\"bindingNavigatorMovePreviousItem.Image\")));");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.Name = \"bindingNavigatorMovePreviousItem\";");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true;");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.Size = new System.Drawing.Size(23, 22);");
            sw.WriteLine("            this.bindingNavigatorMovePreviousItem.Text = \"移到上一条记录\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorSeparator");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorSeparator.Name = \"bindingNavigatorSeparator\";");
            sw.WriteLine("            this.bindingNavigatorSeparator.Size = new System.Drawing.Size(6, 25);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorPositionItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorPositionItem.AccessibleName = \"位置\";");
            sw.WriteLine("            this.bindingNavigatorPositionItem.AutoSize = false;");
            sw.WriteLine("            this.bindingNavigatorPositionItem.Name = \"bindingNavigatorPositionItem\";");
            sw.WriteLine("            this.bindingNavigatorPositionItem.Size = new System.Drawing.Size(50, 21);");
            sw.WriteLine("            this.bindingNavigatorPositionItem.Text = \"0\";");
            sw.WriteLine("            this.bindingNavigatorPositionItem.ToolTipText = \"当前位置\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorSeparator1");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorSeparator1.Name = \"bindingNavigatorSeparator1\";");
            sw.WriteLine("            this.bindingNavigatorSeparator1.Size = new System.Drawing.Size(6, 25);");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorMoveNextItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.Image = ((System.Drawing.Image)(resources.GetObject(\"bindingNavigatorMoveNextItem.Image\")));");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.Name = \"bindingNavigatorMoveNextItem\";");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true;");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.Size = new System.Drawing.Size(23, 22);");
            sw.WriteLine("            this.bindingNavigatorMoveNextItem.Text = \"移到下一条记录\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // bindingNavigatorMoveLastItem");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.Image = ((System.Drawing.Image)(resources.GetObject(\"bindingNavigatorMoveLastItem.Image\")));");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.Name = \"bindingNavigatorMoveLastItem\";");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true;");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.Size = new System.Drawing.Size(23, 22);");
            sw.WriteLine("            this.bindingNavigatorMoveLastItem.Text = \"移到最后一条记录\";");
            sw.WriteLine("            // ");
            sw.WriteLine("            // myPanel1");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.myPanel1.CausesValidation = false;");
            sw.WriteLine("            this.myPanel1.Controls.Add(this.btnSave);");
            sw.WriteLine("            this.myPanel1.Controls.Add(this.btnCancel);");
            sw.WriteLine("            this.myPanel1.Controls.Add(this.bindingNavigator" + dt.TitleCaseName + ");");
            sw.WriteLine("            this.myPanel1.Controls.Add(this.btnClose);");
            sw.WriteLine("            this.myPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;");
            sw.WriteLine("            this.myPanel1.Location = new System.Drawing.Point(0, 162);");
            sw.WriteLine("            this.myPanel1.Name = \"myPanel1\";");
            sw.WriteLine("            this.myPanel1.Size = new System.Drawing.Size(455, 59);");
            sw.WriteLine("            this.myPanel1.TabIndex = 1;");
            sw.WriteLine("            // ");
            sw.WriteLine("            // uc" + dt.TitleCaseName + "Detail1");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1.Dock = System.Windows.Forms.DockStyle.Fill;");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1.Location = new System.Drawing.Point(0, 0);");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1.Name = \"uc" + dt.TitleCaseName + "Detail1\";");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1.TabIndex = 0;");
            sw.WriteLine("            this.uc" + dt.TitleCaseName + "Detail1." + dt.TitleCaseName + "BindingSource = null;");
            sw.WriteLine("            // ");
            sw.WriteLine("            // dlg" + dt.TitleCaseName + "Edit");
            sw.WriteLine("            // ");
            sw.WriteLine("            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);");
            sw.WriteLine("            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;");
            sw.WriteLine("            this.Controls.Add(this.uc" + dt.TitleCaseName + "Detail1);");
            sw.WriteLine("            this.Controls.Add(this.myPanel1);");
            sw.WriteLine("            this.Name = \"dlg" + dt.TitleCaseName + "Edit\";");
            sw.WriteLine("            this.Text = \"编辑对话框\";");
            sw.WriteLine("            this.Load += new System.EventHandler(this.dlg" + dt.TitleCaseName + "Edit_Load);");
            sw.WriteLine("            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.dlg" + dt.TitleCaseName + "Edit_FormClosing);");
            sw.WriteLine("            ((System.ComponentModel.ISupportInitialize)(this.bindingNavigator" + dt.TitleCaseName + ")).EndInit();");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".ResumeLayout(false);");
            sw.WriteLine("            this.bindingNavigator" + dt.TitleCaseName + ".PerformLayout();");
            sw.WriteLine("            this.myPanel1.ResumeLayout(false);");
            sw.WriteLine("            this.myPanel1.PerformLayout();");
            sw.WriteLine("            this.ResumeLayout(false);");
            sw.WriteLine("");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        #endregion");
            sw.WriteLine("");
            sw.WriteLine("        public " + BaseParams.UserControlsNameSpace + ".Details.Uc" + dt.TitleCaseName + "Detail uc" + dt.TitleCaseName + "Detail1;");
            sw.WriteLine("        private " + BaseParams.ControlsNameSpace + ".MyButton btnSave;");
            sw.WriteLine("        private " + BaseParams.ControlsNameSpace + ".MyButton btnCancel;");
            sw.WriteLine("        private " + BaseParams.ControlsNameSpace + ".MyButton btnClose;");
            sw.WriteLine("        private System.Windows.Forms.BindingNavigator bindingNavigator" + dt.TitleCaseName + ";");
            sw.WriteLine("        private System.Windows.Forms.ToolStripLabel bindingNavigatorCountItem;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripButton bindingNavigatorMoveFirstItem;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripButton bindingNavigatorMovePreviousItem;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripTextBox bindingNavigatorPositionItem;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator1;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripButton bindingNavigatorMoveNextItem;");
            sw.WriteLine("        private System.Windows.Forms.ToolStripButton bindingNavigatorMoveLastItem;");
            sw.WriteLine("        private " + BaseParams.ControlsNameSpace + ".MyPanel myPanel1;");
            sw.WriteLine("");
            sw.WriteLine("    }");
            sw.WriteLine("}");

            sw.Close();
            file.Close();
            #endregion

        }
    }
}
